package com.itheima.springbootwebtlias.config;

import com.itheima.springbootwebtlias.interceptor.MyInterceptor;
import com.itheima.springbootwebtlias.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//springmvc配置类：配置拦截器，视图解析器，消息转换器等等
@Configuration  //标识当前类是配置类，spring框架扫描配置类，使用设置的配置
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private MyInterceptor myInterceptor;

    @Autowired
    private TokenInterceptor tokenInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry
                .addInterceptor(myInterceptor) //注册拦截器
                .addPathPatterns("/**");  //配置拦截器的拦截路径 ，/** 表示所有路径
        registry
                .addInterceptor(tokenInterceptor) //注册拦截器
                .addPathPatterns("/**") //配置拦截器的拦截路径 ，/** 表示所有路径
                .excludePathPatterns("/login"); //配置不拦截的多个路径（开了一个小门，直接放行）

    }
}
